//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __XLLP_OST_H__
#define __XLLP_OST_H__

/*++
"This software program is available to you under a choice of one of two 
licenses.  You may choose to be licensed under either the GNU General Public 
License (GPL) Version 2, June 1991, available at 
http://www.fsf.org/copyleft/gpl.html, or the BSD License, the text of
which follows:

Copyright (c) 1996-2005, Intel Corporation. All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this 
list of conditions and the following disclaimer. 

Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or 
other materials provided with the distribution. 

Neither the name of the Intel Corporation ("Intel") nor the names of its 
contributors may be used to endorse or promote products derived from this
software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
--*/

#include "xllp_defs.h"

//
// OST Register Definitions
//
typedef struct
{
    XLLP_VUINT32_T    osmr0;         	//OS timer match register 0
    XLLP_VUINT32_T    osmr1;         	//OS timer match register 1
    XLLP_VUINT32_T    osmr2;         	//OS timer match register 2
    XLLP_VUINT32_T    osmr3;          	//OS timer match register 3
    XLLP_VUINT32_T    oscr0;            //OS timer counter register 0(compatible)
    XLLP_VUINT32_T    ossr;             //OS timer status register
    XLLP_VUINT32_T    ower;          	//OS timer watchdog enable register
    XLLP_VUINT32_T    oier;           	//OS timer interrupt enable register
    XLLP_VUINT32_T    osnr;           	//OS timer snapshot register
    XLLP_VUINT32_T    reserved1[7];
    XLLP_VUINT32_T    oscr4;		//OS timer counter register 4
    XLLP_VUINT32_T    oscr5;		//OS timer counter register  5
    XLLP_VUINT32_T    oscr6;		//OS timer counter register  6
    XLLP_VUINT32_T    oscr7;		//OS timer counter register  7
    XLLP_VUINT32_T    oscr8;		//OS timer counter register  8
    XLLP_VUINT32_T    oscr9;		//OS timer counter register  9
    XLLP_VUINT32_T    oscr10;		//OS timer counter register  10
    XLLP_VUINT32_T    oscr11;		//OS timer counter register  11
    XLLP_VUINT32_T    reserved2[8];
    XLLP_VUINT32_T    osmr4;		//OS timer match register 4
    XLLP_VUINT32_T    osmr5;		//OS timer match register 5
    XLLP_VUINT32_T    osmr6;		//OS timer match register 6
    XLLP_VUINT32_T    osmr7;		//OS timer match register 7
    XLLP_VUINT32_T    osmr8;		//OS timer match register 8
    XLLP_VUINT32_T    osmr9;		//OS timer match register 9
    XLLP_VUINT32_T    osmr10;		//OS timer match register 10
    XLLP_VUINT32_T    osmr11;		//OS timer match register 11
    XLLP_VUINT32_T    reserved3[8];
    XLLP_VUINT32_T    omcr4;		//OS timer match control register 4
    XLLP_VUINT32_T    omcr5;		//OS timer match control register 5
    XLLP_VUINT32_T    omcr6;		//OS timer match control register 6
    XLLP_VUINT32_T    omcr7;		//OS timer match control register 7
    XLLP_VUINT32_T    omcr8;		//OS timer match control register 8
    XLLP_VUINT32_T    omcr9;		//OS timer match control register 9
    XLLP_VUINT32_T    omcr10;		//OS timer match control register 10
    XLLP_VUINT32_T    omcr11;		//OS timer match control register 11
} XLLP_OST_T, *P_XLLP_OST_T;


//
// Enumeration for compatible OST match registers
//
typedef enum 
{
    MatchReg0 = 0,
    MatchReg1,
    MatchReg2,
    MatchReg3,
    MatchReg4,
    MatchReg5,
    MatchReg6,
    MatchReg7,
    MatchReg8,
    MatchReg9,
    MatchReg10,
    MatchReg11
}XLLP_OST_MATCHREG;

//
// OST Bit Definitions
//

//
// OST Tick constants
//
#define XLLP_OST_TICKS_MS    3250          // 1ms in ticks (3.25x10^6tick/sec * 1/1000sec/msec)
#define XLLP_OST_TICKS_US    3             // 1usec in ticks (3.25x10^6tick/sec * 1/1000000sec/usec)

//
// OSSR Bits
//
#define XLLP_OSSR_M0			(0x1 << 0)
#define XLLP_OSSR_M1			(0x1 << 1)
#define XLLP_OSSR_M2			(0x1 << 2)
#define XLLP_OSSR_M3			(0x1 << 3)
#define XLLP_OSSR_M4			(0x1 << 4)
#define XLLP_OSSR_M5			(0x1 << 5)
#define XLLP_OSSR_M6			(0x1 << 6)
#define XLLP_OSSR_M7			(0x1 << 7)
#define XLLP_OSSR_M8			(0x1 << 8)
#define XLLP_OSSR_M9			(0x1 << 9)
#define XLLP_OSSR_M10			(0x1 << 10)
#define XLLP_OSSR_M11			(0x1 << 11)

#define XLLP_OSSR_RESERVED_BITS (0xFFFFF000)

//
// OIER Bits
//
#define XLLP_OIER_E0			(0x1 << 0)
#define XLLP_OIER_E1			(0x1 << 1)
#define XLLP_OIER_E2			(0x1 << 2)
#define XLLP_OIER_E3			(0x1 << 3)
#define XLLP_OIER_E4			(0x1 << 4)
#define XLLP_OIER_E5			(0x1 << 5)
#define XLLP_OIER_E6			(0x1 << 6)
#define XLLP_OIER_E7			(0x1 << 7)
#define XLLP_OIER_E8			(0x1 << 8)
#define XLLP_OIER_E9			(0x1 << 9)
#define XLLP_OIER_E10			(0x1 << 10)
#define XLLP_OIER_E11			(0x1 << 11)

#define XLLP_OIER_RESERVED_BITS (0xFFFFF000)

//
// OMCR 4-11
//
#define XLLP_OMCR_CRES_REG			(0x1)
#define XLLP_OMCR_CRES_1MSEC		(0x2)
#define XLLP_OMCR_CRES_1USEC		(0x4)
#define XLLP_OMCR_CRES_1SEC			(0x3)

#define XLLP_OMCR_R					(0x1 << 3)
#define XLLP_OMCR_S					(0x3 << 4)
#define XLLP_OMCR_P					(0x1 << 6)
#define XLLP_OMCR_C					(0x1 << 7)

#define XLLP_OMCR_RESERVED_BITS		(0xFFFFFF00)


#ifdef __cplusplus
extern "C"
{
#endif
//
// XLLP OST Prototypes
//
void XllpOstConfigureTimer 
  (P_XLLP_OST_T pOSVirtualAddress, XLLP_OST_MATCHREG matchreg, XLLP_UINT32_T matchvalue);

void XllpOstConfigureMatchReg
  (P_XLLP_OST_T pOSVirtualAddress, XLLP_OST_MATCHREG matchreg, XLLP_UINT32_T matchincrement);

void XllpOstDelayMicroSeconds 
     (P_XLLP_OST_T pOstRegs, XLLP_UINT32_T microseconds);

void XllpOstDelayMilliSeconds 
     (P_XLLP_OST_T pOstRegs, XLLP_UINT32_T milliseconds);

extern XLLP_STATUS_T XllpOSTSave(P_XLLP_OST_T pVirtual, P_XLLP_OST_T pSave);
extern XLLP_STATUS_T XllpOSTRestore(P_XLLP_OST_T pVirtual, P_XLLP_OST_T pSave);

#ifdef __cplusplus
}
#endif

#endif
